package com.bracketbird.server.jdo.club;

import com.bracketbird.server.dao.*;
import com.google.appengine.api.datastore.Key;
import com.bracketbird.clientcore.util.*;

import javax.jdo.annotations.*;
import java.util.*;

/**
 *
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class TournamentJDO extends JDO {


    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private com.google.appengine.api.datastore.Key key;

    //foreign key
    @Persistent
    private com.google.appengine.api.datastore.Key clubKey;

    //foreign key
    @Persistent
    private com.google.appengine.api.datastore.Key tournamentChannelKey;


    //is template or tournament
    @Persistent
    private Boolean template;

    @Persistent
    private String name;


    @Persistent(defaultFetchGroup = "true")
    private List<Key> levels = new ArrayList<Key>();


    //playingTeamJDO keys
    @Persistent(defaultFetchGroup = "true")
    private List<Key> playingTeams = new ArrayList<Key>();


    @Persistent
    private Date createdDate;

    @Persistent
    private Date lastChangeDate;


    public TournamentJDO() {

    }

    public com.google.appengine.api.datastore.Key getKey() {
        return key;
    }

    public void setKey(Key key) {
        this.key = key;
    }

    public Key getClubKey() {
        return clubKey;
    }

    public void setClubKey(Key clubKey) {
        this.clubKey = clubKey;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public Date getLastChangeDate() {
        return lastChangeDate;
    }

    public void setLastChangeDate(Date lastChangeDate) {
        this.lastChangeDate = lastChangeDate;
    }

    public List<Key> getLevels() {
        return levels;
    }

    public void setLevels(List<Key> levels) {
        this.levels = levels;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getTemplate() {
        return template;
    }

    public void setTemplate(Boolean template) {
        this.template = template;
    }

    public List<Key> getPlayingTeams() {
        return playingTeams;
    }

    public void setPlayingTeams(List<Key> playingTeams) {
        this.playingTeams = playingTeams;
    }

    public Key getTournamentChannelKey() {
        return tournamentChannelKey;
    }

    public void setTournamentChannelKey(Key tournamentChannelKey) {
        this.tournamentChannelKey = tournamentChannelKey;
    }

    @Override
    public String toString() {
        return "TournamentJDO{" +
                "\n  tournamentlevels=" + StringUtil.toString(levels) +
                "  Teams=" + StringUtil.toString(playingTeams) +
                "}\n";
    }

    public void toString(StringBuffer sb, int tab) {
        WriterIt.appendTab(sb, tab);
        sb.append("TournamentJDO\n");
        WriterIt.append(sb, "teams", playingTeams, tab + 1);
        WriterIt.append(sb, "tournamentlevels", levels, tab + 1);


    }
}